package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author wyh
 * @Date 2025/5/8 20:48
 * @description:
 */
@Configuration
public class DirectConfiguration {
    // 声明FanoutExchange交换机
    @Bean
    public DirectExchange directExchange() {
//        return ExchangeBuilder.fanoutExchange("fanout.hmall").build();
        return new DirectExchange("direct.hmall");
    }

    // 声明队列
    @Bean
    public Queue directQueue1() {
//        return QueueBuilder.durable("fanout.queue1").lazy().build();
        return new Queue("direct.queue1");
    }

    // 声明队列与交换机的绑定关系
    @Bean
    public Binding DirectBinding1(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("red");
    }
    @Bean
    public Binding DirectBinding2(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("yellow");
    }
//    @Bean
    public Queue lazyQueue(){
        return QueueBuilder
                .durable("lazy.queue")
                .lazy() // 开启Lazy模式
                .build();
    }

}
